package com.java.huxb.backend.cinema.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java.huxb.backend.cinema.dao.entity.MoocCinemaT;
import com.java.huxb.backend.cinema.dao.mapper.MoocCinemaTMapper;
import com.java.huxb.backend.cinema.service.CinemaServiceAPI;
import com.java.huxb.backend.utils.exception.CommonServiceException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.xml.ws.RequestWrapper;

/**
 * @author huxb
 * @date 2020/1/29 0029 下午 6:03
 */
@Service
public class CinemaServiceImpl implements CinemaServiceAPI {

    @Resource
    private MoocCinemaTMapper cinemaTMapper;

    @Override
    public IPage<MoocCinemaT> findPageBy(Page page) {

        QueryWrapper queryWrapper = new QueryWrapper();
        return cinemaTMapper.selectPage(page, queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addCinema(MoocCinemaT moocCinemaT) {
        cinemaTMapper.insert(moocCinemaT);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void editCinema(MoocCinemaT moocCinemaT) throws CommonServiceException {
        MoocCinemaT cinemaForUpdate = cinemaTMapper.selectById(moocCinemaT.getUuid());
        if (cinemaForUpdate == null){
            throw new CommonServiceException(401, "该信息不存在");
        }
        cinemaTMapper.updateById(moocCinemaT);
    }
}
